<template>
  <nav id="navbar">
    <router-link v-for="l in locations" :key="l.icon" :to="l.router" active-class="current">
      <i :class="`fa fa-${l.icon}`"></i>
      <span>{{l.description}}</span>
    </router-link>
  </nav>
</template>

<script>
export default {
  name: 'Navbar',
  data(){
    return {
      locations: [
        {
          icon: 'search',
          description: '调研分析',
          router: '/survey'
        },
        {
          icon: 'map',
          description: '住区规划',
          router: 'plan'
        },
        {
          icon: 'home',
          description: '住宅设计',
          router: 'design'
        }
      ]
    }
  },
  methods:{
    flowUp(){
      const navbar = document.getElementById('navbar')
      navbar.style.bottom = 'calc(50vh - min(25vw, 25vh) - 6rem)'
    },
    flowDown(){
      const navbar = document.getElementById('navbar')
      navbar.style.bottom = 'calc(1rem + env(safe-area-inset-bottom))'
    }
  },
  mounted(){
    this.$bus.$on('flowUp', this.flowUp)
    this.$bus.$on('flowDown', this.flowDown)
  }
}
</script>

<style scoped>
#navbar{
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  width: min(80vw, 80vh);
  height: 3rem;
  border-radius: 2rem;
  box-shadow: 0px 16px 48px rgba(50, 50, 50, 0.2);
  position: fixed;
  left: calc(50vw - min(40vw, 40vh));
  bottom: calc(50vh - min(25vw, 25vh) - 6rem);
  overflow: hidden;
  z-index: 100;
  animation: flowIn 1.5s ease-out;
  transition: bottom 1s cubic-bezier(0.71, -0.22, 0.23, 1);
}

#navbar > a{
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--yellow);
  width: 34%;
  height: inherit;
  background: white;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
}

#navbar > a > i{
  margin: 0.2rem 0.5rem;
}

#navbar > a:hover, #navbar > a.current{
  color: white;
  background: var(--yellow);
}

#navbar > a:hover > i, #navbar > a:hover > span{
  animation: jump 0.8s ease-out;
}

@media screen and (max-width: 767px) {
  #navbar > a{
    flex-direction: column;
  }

  #navbar > a > span{
    font-size: 0.25rem;
    font-weight: normal;
  }
}

@keyframes jump {
  40%{
    transform: translateY(-40%);
  }
}

@keyframes flowIn{
  0%{
    opacity: 0;
    transform: translateY(2rem);
  }
  30%{
    opacity: 1;
  }
  40%{
    transform: translateY(-0.5rem);
  }
}

</style>